/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sim.execution;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import sim.helpers.statistics.Parser;

/**
 *
 * @author artem
 */
public class MultipleExec {

    public static String changingVariable = "";
    public static int repetitions;
    public static String[] values;
//    private static String properties = "E:\\Documents\\NetbeansProjects\\sim\\src\\sim\\execution\\default.properties";
    private static String properties = "/home/artem/Documents/Win Docs/NetbeansProjects/sim/src/sim/execution/default.properties";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        getInitials();
        Parser parser = new Parser(properties);
        parser.setVariable(changingVariable);
        for (int i = 0; i < repetitions; i++) {
            System.out.println("\n**** Performing execution " + (i + 1) + "/" + repetitions + " ****");
            changeVariable(i);
            SingleExecution se = new SingleExecution(properties);
            se.execute(args);
            parser.setIndex(i);
            parser.parseSingle();
        }
        parser.parseMultiple();
    }

    private static void getInitials() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter your upper level changing variable [QOS, N, SD, L, Rep] (default QoS): ");
        changingVariable = in.nextLine().trim().toUpperCase();
        if (changingVariable.equals("")) {
            changingVariable = "QOS";
        }
        System.out.print("Enter the changing variable values separated by a single space: ");
        values = in.nextLine().split(" ");
        repetitions = values.length;
    }

    private static void changeVariable(int index) {
        Properties config = new Properties();
        String variable = "";
        try {
            config.load(new java.io.FileInputStream(properties));
            if (changingVariable.equalsIgnoreCase("qos")) {
                variable = "QOS";
            } else if (changingVariable.equalsIgnoreCase("sd")) {
                variable = "SD";
            } else if (changingVariable.equalsIgnoreCase("n")) {
                variable = "NODES";
            } else if (changingVariable.equalsIgnoreCase("l")) {
                variable = "LENGTH";
            } else if (changingVariable.equalsIgnoreCase("Rep")) {
                variable = "HEADS";
            } else {
                variable = "NODES";
            }
            System.out.println("Changing " + variable + " to " + values[index]);
            config.setProperty(variable, values[index]);
            config.store(new FileOutputStream(properties), null);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MultipleExec.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MultipleExec.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
